<script setup lang="ts">
import type { YearGroup } from '@/types/archived';

defineProps<{
  archives: YearGroup[];
  loading: boolean;
}>();
</script>

<template>
    <div class="archive-header">
      <h1 class="title">文章归档</h1>
      <div class="stats">
        共计 <span>{{ archives.length + 1 }}</span> 篇文章
      </div>
    </div>
    <div v-if="loading" class="loading-state">
      <div class="loading-spinner"></div>
      <div class="loading-text">正在加载文章...</div>
    </div>
    <div v-else-if="archives.length === 0" class="empty-state">
      <div class="empty-icon">📝</div>
      <div class="empty-text">暂无文章</div>
      <div class="empty-desc">快去发布你的第一篇文章吧！</div>
    </div>
  <div v-else class="archive-timeline">
    <div
      v-for="yearGroup in archives"
      :key="yearGroup.year"
      :id="`year-${yearGroup.year}`"
      class="year-group"
    >
      <div class="year-header">
        <h2>{{ yearGroup.year }}</h2>
        <span class="count">{{ yearGroup.count }} 篇</span>
      </div>

      <div
        v-for="monthGroup in yearGroup.months"
        :key="`${yearGroup.year}-${monthGroup.month}`"
        :id="`month-${yearGroup.year}-${monthGroup.month}`"
        class="month-group"
      >
        <h3 class="month-title">{{ monthGroup.month }} 月</h3>
        <ul class="article-list">
          <li
            v-for="article in monthGroup.articles"
            :key="article.id"
            class="article-item"
          >
            <span class="article-date">{{ new Date(article.publishTime).getDate() }} 日</span>
            <router-link
              :to="`/detail/${article.slug}?id=${article.id}`"
              class="article-title"
            >
              {{ article.title }}
            </router-link>
            <span class="article-views">
                    🔥 {{ article.views }}
                  </span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eaecef;

  .title {
    font-size: 24px;
    font-weight: 600;
    color: #2c3e50;
  }

  .stats {
    font-size: 14px;
    color: #6b7280;

    span {
      color: #60a5fa;
      font-weight: 500;
    }
  }
}

// 加载状态样式优化
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;

  .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(96, 165, 250, 0.1);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  .loading-text {
    margin-top: 16px;
    color: #6b7280;
    font-size: 14px;
  }
}

// 空状态样式
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;

  .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.8;
  }

  .empty-text {
    font-size: 18px;
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 8px;
  }

  .empty-desc {
    font-size: 14px;
    color: #6b7280;
  }
}

.archive-timeline {
  position: relative;
  padding-left: 32px;

  &::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 7px;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg,
    #60a5fa 0%,
    rgba(96, 165, 250, 0.6) 50%,
    rgba(96, 165, 250, 0.3) 100%);
  }

  .year-group {
    position: relative;
    margin-bottom: 40px;

    &::before {
      content: '';
      position: absolute;
      left: -27.5px;
      top: 6px;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: #60a5fa;
      border: 3px solid #fff;
      box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
      z-index: 1;
    }

    .year-header {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 24px;

      h2 {
        font-size: 20px;
        font-weight: 600;
        color: #2c3e50;
      }

      .count {
        font-size: 14px;
        color: #6b7280;
        background: rgba(96, 165, 250, 0.08);
        padding: 2px 8px;
        border-radius: 12px;
      }
    }

    .month-group {
      position: relative;
      margin-left: 24px;
      margin-bottom: 32px;

      &::before {
        content: '';
        position: absolute;
        left: -49px;
        top: 6px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #60a5fa;
        opacity: 0.9;
        border: 2px solid #fff;
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
      }

      .month-title {
        font-size: 16px;
        font-weight: 500;
        color: #4b5563;
        margin-bottom: 16px;
      }

      .article-list {
        .article-item {
          position: relative;
          display: flex;
          align-items: center;
          padding: 12px 16px;
          border-radius: 8px;
          transition: all 0.3s ease;

          &::before {
            content: '';
            position: absolute;
            left: -46px;
            top: 50%;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: #60a5fa;
            opacity: 0.8;
            transform: translateY(-50%);
            transition: all 0.3s;
          }

          &:hover {
            background: rgba(96, 165, 250, 0.08);
            transform: translateX(8px);

            &::before {
              opacity: 0.8;
              transform: translateY(-50%) scale(1.3);
            }

            .article-title {
              color: #60a5fa;
            }
          }

          .article-date {
            font-size: 14px;
            color: #6b7280;
            margin-right: 16px;
            min-width: 40px;
          }

          .article-title {
            flex: 1;
            font-size: 15px;
            color: #2c3e50;
            text-decoration: none;
            transition: color 0.3s ease;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-right: 16px;
          }

          .article-views {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 4px;
            padding: 4px 10px;
            border-radius: 12px;
            background: rgba(96, 165, 250, 0.08);
            color: #6b7280;
            font-size: 14px;
            min-width: 80px;
            width: 80px;
            transition: all 0.3s ease;

            &:hover {
              background: rgba(96, 165, 250, 0.12);
            }
          }
        }
      }
    }
  }
}
// 加载动画
.loading-state {
  display: flex;
  justify-content: center;
  padding: 40px 0;

  .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(96, 165, 250, 0.1);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
}
</style>
